<?php

ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once '../../../sql/connection.php';

$id = $_POST['editID'];
$editTitle = $_POST['editTitle'];
$editDes = $_POST['editDes'];
$editQType = $_POST['editQType'];
$editQType = (int)$editQType;

if ($editQType == 1){
	$editOpt1 = $_POST['editOpt1'];
	$editOpt2 = $_POST['editOpt2'];
	$editOpt3 = $_POST['editOpt3'];
	$editOpt4 = $_POST['editOpt4'];
	$editOptAnswer = $_POST['editOptAnswer'];
	$editComAnswer = "";
}
else{
	$editOpt1 = "";
	$editOpt2 = "";
	$editOpt3 = "";
	$editOpt4 = "";
	$editOptAnswer = "";
	$editComAnswer = $_POST['editComAnswer'];
}

$now = date('Y-m-d H:i:s', time());
$editSql = "UPDATE question_info SET update_time = '$now',  question_title = '$editTitle',question_description = '$editDes' , question_type = '$editQType',
                          question_opt_A = '$editOpt1',question_opt_B = '$editOpt2',question_opt_C = '$editOpt3', question_opt_D = '$editOpt4',
                       question_opt_answer  = '$editOptAnswer', question_completion_answer = '$editComAnswer' where id = '$id' ";


if (mysqli_query($GLOBALS['conn'], $editSql)) {
	echo "
            <script>
                alert('修改成功！');
                window.location.href=document.referrer;
            </script>
        ";
} else {
	echo "
            <script>
                alert('修改失败！');
                history.back();
            </script>
        ";
}


